<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/4/1
 * Time: 13:42
 */
namespace app\admin\controller;
use think\Db;
class Medal extends Base {
    public function index(){
        if(request()->isAjax ()){
            extract(input());
//            $Nowpage = input('page') ? input('page'):1;
//            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('honor')->alias('h')
                ->join('up_coupon c', 'c.coupon_id = h.coupon_id', 'left')
                ->count();
            $lists = Db::name('honor')->alias('h')
                ->join('up_coupon c', 'c.coupon_id = h.coupon_id', 'left')
//                ->page($Nowpage,$limits)
//                ->order('exchange_id desc')
                ->select ();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch();
    }
    /*
       * 编辑轮播图
       */
    public function update(){
        if(request()->isPost ()){
            extract(input());
            $param = [
                'thumb'=>$img1,
                'thumb_light'=>$img,
                'name'=>$lb_name,
                'miaoshu' => $miaoshu,
                'exp' => $exp,
                'coupon_id' => $coupon_id
            ];
            $res = Db::name('honor')->where('id',$id)->update($param);
            if($res){
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $info = Db::name('honor')
            ->where(['id'=>input('id')])
            ->find();
        $coupon = Db::table('up_coupon')
            ->where('coupon_status', 1)
            ->where('coupon_online', 1)
            ->where('coupon_type', 4)
            ->field('coupon_id, coupon_name')
            ->select();
        $this->assign([
           'info' => $info,
            'coupon' => $coupon
        ]);
        return $this->fetch('medal/update');
    }
}